AppleScript™ offers Mac® users a powerful way to automate tasks and share information. PowerKey® Pro extends the power of AppleScript in two important ways. You can schedule scripts with PowerKey Events, and you can even control PowerKey Pro itself with scripts. The “Sample Scripts” folder in the same folder as this document contains several useful examples showing how to use AppleScript with PowerKey Pro.
TIP: In addition to AppleScript, you can control the PowerKey software with any scripting language that supports the Apple Event Object Model.
Running AppleScripts in Events
The PowerKey software allows you to run a script in any Event. You can use this ability to run scripts on a time schedule, or in response to system activity (for example, when the phone rings or you type a keystroke).
To use a script, save it as a “compiled script” in the Script Editor. You may find it handy to place scripts in the PowerKey Folder (in your Preferences folder), but they can be placed anywhere on your hard disk. To run the script, create an Execute Script Action in the desired Event(s).
NOTE: If your script opens a dialog box to display or request information, you will not be able to run it as a compiled script. This is because the PowerKey Extension runs as a background-only application, which cannot draw windows. To run such a script, save it as an “application” in the Script Editor, and run it with the Open File Action.
Controlling PowerKey Pro with AppleScript
In addition to running scripts from the PowerKey software, you can control PowerKey Pro directly from scripts. To control PowerKey, place a tell block in your script as follows:
tell application "PowerKey Extension"
...
end tell
You can then place PowerKey scripting commands inside this block.
The PowerKey software defines several classes of objects for use by AppleScripts. A unit is a single PowerKey Pro, which contains several outlets and events. Units and outlets may be specified by name or number, but events should be specified only by name. You must specify a unit even if you only have one PowerKey Pro connected to your computer.
For more information on PowerKey classes, use the “Open Dictionary” command in the Script Editor’s File menu, and open the PowerKey Extension (not Editor) in your system’s Extensions folder.
Setting Outlets
To set an outlet’s state, you set the level property of a unit’s outlet to 0 (for off) or 100 (for on).
set level of outlet 2 of unit 1 to 100
set level of outlet named "Modem" of unit 1 to 0
You must specify both the outlet and the unit, even if you only have one PowerKey Pro. You can refer to outlets and units by number or name.
Reading Current Outlet States
To find out if an outlet is on or off, you can get the level property of a unit’s outlet.
get level of outlet named "Modem" of unit 1
The result variable will contain 0 (if the outlet is off) or 100 (if the outlet is on).
Suspending and Resuming Events
You can suspend and resume Events by setting the enabled property of a unit’s event to true or false.
set enabled of event named "Morning Wakeup" to false
You can also check to see if an Event is suspended by getting the property.
Executing Events
You can execute an Event immediately in a script. The Trigger and Qualifiers are ignored, and all Actions are performed in sequence.
execute event named "Toggle Modem" of unit 1
Setting the User Timer
The PowerKey software also defines a user timer. You can set this timer with a number of seconds, and the software will immediately begin counting down.
set timer to 300
NOTE: This feature is only useful if you own the Server Restart Option, where it can be used with the When Timer Expires Trigger. See the “READ ME — Server Restart Option” document on the PowerKey master disk or updater folder for more information.
When the user timer reaches zero, any Events with a When Timer Expires Trigger will execute.
This feature was designed for use by custom software such as databases or interactive presentations. The software can periodically “ping” the PowerKey software by setting the user timer. If the software crashes or fails, an Event can restart the computer.
If you wish to use this feature, but are not running AppleScript, you can send a simple Apple Event to the PowerKey software. This Apple Event should have an Event Class of ‘PKPr’ and an Event ID of ‘Tick’.
The files in this package may not be redistributed in any way without express permission from Sophisticated Circuits, Inc.
PowerKey is a registered trademark, and Server Restart Option is a trademark of Sophisticated Circuits, Inc. Mac and AppleScript are registered trademarks of Apple Computer, Inc.